<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <link rel="stylesheet" href="/quanliadmin/docroot/css/storage.css" type="text/css" media="screen" />
    <title>日常管理--货品上架</title>
</head>

<body>

<!--{include file='comm/naviBanner.tpl'}-->

<div class="container">

    <!--{include file='comm/menu.tpl'}-->

        <div class="comm_crub">
            <span class="now_crub">日常管理--货品上架</span>
        </div>

        <div style="padding: 10px;">

        <div class="panel panel-default">
            <div class="panel-heading">正在操作：日常管理--货品上架</div>
            <div class="panel-body">


                <form id="goodsUp_form" onsubmit="return false;" class="form-horizontal" >

                    <div class="form-group">
                        <label for="storeID" class="col-sm-2 control-label">选择仓库 <font color="red">*</font></label>
                        <div class="col-sm-10">
                            <select class="form-control col-sm-2" id='storeID' name='storeID' style="width: 200px;">
                                <option value=''>请选择</option>
                                <!--{foreach from=$store_array item=value}-->
                                <option value='<!--{$value->storeID}-->'<!--{if $storeID == $value->storeID}--> selected <!--{/if}--> ><!--{$value->storeName}--></option>
                                <!--{/foreach}-->
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="shelf_name" class="col-sm-2 control-label">货位号 <font color="red">*</font></label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="shelf_name" id="shelf_name" style="width:200px;" value="" onkeypress="getEvent(1,event);">
                            <span class="help-block" id="shelfError">&nbsp;<font color="red"  style="font-size:13px;">输入后回车</font></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="goods" class="col-sm-2 control-label">商品SKU <font color="red">*</font></label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="goods" id="goods" style="width:200px;" value="" onkeypress="getEvent(2,event);">
                            <span class="help-block" id="goodsError">&nbsp;<font color="red" id="goodsError" style="display: none;">扫描或回车可绑定货位号</font></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <input type="button" class="btn btn-primary" onclick="goodsUp.check();" value="保存" />
                        </div>
                    </div>
                </form>

            </div>
        </div>

        </div>


</div>

<script type="text/javascript">

    //仓库选择事件
    $("#storeID").change(function (){
        var storeID = $(this).val();

        if( storeID != -1 )
            $("#shelf_name").focus();

    });

    /**
     * 输入框回车事件
     * flg 1:货位号   2：商品货号或条形码
     */
    function getEvent(flg , e){

        if( e.keyCode == 13 ){

            if( flg == 1 ){
                var error_msg = "";
                var storeID  = $.trim($("#storeID").val());
                if(storeID == "-1"){
                    error_msg += "请选择仓库<br />";
                }

                var shelf_name = $("#shelf_name").val();
                if( shelf_name == '' ){
                    error_msg += '请输入货位号<br/>';
                }

                if(error_msg != ''){
                    E.alert(error_msg);
                    return false;
                }
                goodsUp.shelfCheck(storeID,shelf_name);
            }else{

                var goods = $("#goods").val();

                if( goods == '' ){
                    E.alert('请输入商品SKU');
                    return false;
                }else{
                    goodsUp.check();
                }

            }

        }

    }

    //上架数量回车事件
    $("#amount").keydown(function(e){

        if(e.keyCode == 13 ){

            var value = $.trim( $(this).val() );

            var error_msg = '';

            if( value == '' ){
                error_msg += "请输入上架数量<br />";
            }else{

                if( !E.isInt(value) )
                    error_msg += "上架数量格式有误<br />";

            }

            if( error_msg != '' ){
                E.alert(error_msg);
                return false;
            }

            goodsUp.check();

        }

    })

    var goodsUp = {

        dt: "",

        storeID:-1,

        check: function() {

            this.dt = E.getFormValues("goodsUp_form");
            var error_msg = "";
            var goodsType = $("#goodsType").val();

            if( this.dt.storeID == ""){
                error_msg += "请选择仓库<br />";
            }

            if (this.dt.shelf_name == ""){
                error_msg += "货位号不能为空<br />";
            }

            if (this.dt.goods == ""){
                if( goodsType == 1 ){
                    error_msg += "请输入商品编号<br />";
                }else{
                    error_msg += "请输入商品条码<br />";
                }

            }

            if (error_msg != "")
                E.alert(error_msg);
            else {
                this.add();
            }

        },

        add: function() {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/wms/store.ajax?operFlg=12",
                dataType: "JSON",
                data: this.dt,
                success: function( result_obj ) {
                    if (result_obj.code == 200) {

                        E.alert(result_obj.message , 2 , "goodsUp.load");


                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        /**
         * 检查货位号
         * @param storeID       仓库ID
         * @param shelf_name    货位号
         * @returns {boolean}
         */
        shelfCheck:function(storeID,shelf_name){
            jquery_ajax(11,{storeID:storeID,shelf_name:shelf_name},goodsUp.shelfReturn);
        },

        shelfReturn:function(obj){

            if( obj.code == 200 ){
                document.getElementById('goods').disabled = false;
                $("#shelfError").text('');
               $("#goods").focus();
                $("#goodsError").show();
            }else{
               $("#shelfError").text(obj.message);
                $("#goodsError").hide();
            }

        },

        load:function(){
            $("#storeID").val(this.storeID);
            $("#shelf_name").val('');
            $("#shelfError").text('输入后回车');
            $("#goodsType").val(1);
            $("#goods").val('');
            $("#amount").val('');
            $("#shelf_name").focus();
            $("#goodsError").hide();
        }

    };

    function jquery_ajax(flg,data,func){
        $.ajax({
            type: "post",
            url: "/invokingAjax-backend/wms/store.ajax?operFlg="+flg,
            dataType: "json",
            data: data,
            success: function( result_obj ) {
                func(result_obj);
            },
            error : function(msg){
                alert('网络不给力，请重新尝试...');
            }
        });
    }


</script>

</body>

</html>
